package com.xiaolin.sports;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.xiaolin.sports.utils.HttpClientUtils;
import com.xiaolin.sports.utils.TextUtil;
import com.xiaolin.sports.wechat.message.FirstButtonMenu;
import com.xiaolin.sports.wechat.message.MenuList;

public class PushMenuService {
	
	public static void main(String[] args) {
		menu20170407();
	}
	
	public static void menu20170407() {
		MenuList menuList = new MenuList();
		List<FirstButtonMenu> firstButtonMenus = new ArrayList<>();
		
		FirstButtonMenu firstButtonMenu01 = new FirstButtonMenu();
		firstButtonMenu01.setName("🌏关于小林");
		firstButtonMenu01.setType("view");
		firstButtonMenu01.setUrl("https://mp.weixin.qq.com/s/8yB2ARNI9vXn8GHSMmLllg");
		firstButtonMenus.add(firstButtonMenu01);
		
		FirstButtonMenu firstButtonMenu02 = new FirstButtonMenu();
		firstButtonMenu02.setName("🏩精品课程");
		firstButtonMenu02.setType("view");
		firstButtonMenu02.setUrl("http://m.xiaolinsports.com//course");
		firstButtonMenus.add(firstButtonMenu02);
		
		FirstButtonMenu firstButtonMenu03 = new FirstButtonMenu();
		firstButtonMenu03.setName("🏂名教风采");
		firstButtonMenu03.setType("view");
		firstButtonMenu03.setUrl("http://m.xiaolinsports.com/media/coach");
		firstButtonMenus.add(firstButtonMenu03);
		menuList.setButton(firstButtonMenus);
		
		pushMenu(menuList);
	}
	
	private static void pushMenu(MenuList menuList) {
		try {
			String acc = "AkObeIEQ6grLkxMRCORtCazY6to5G8mQ42Qowh1LyrdP9tDCk0rS_-OeUh5rVrHp1Oi1uqfmGFcyqUJO-rb7L9ThctXn8At2xz2ivRRm8PVXpzkJdGgxNIK4M7cSBmwVFHDhADAZBX";//WechatUtils.getWechatModel().getAccessToken();
			String json = JSONObject.toJSONString(menuList);
			String url = TextUtil.format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", acc);
			String result = HttpClientUtils.postStringJosn(url, json);
			System.out.println(result);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
